<template>
	<view>
		<ttBar leftIcon="icon-back" :title="type==1?'消费券':'体验码'"></ttBar>
		<view class="box">
			<canvas canvas-id="qrcode" style="width: 215px;height: 215px;" />
			<text>{{type==1?"消费券号":"体验码"}}：{{code}}</text>
		</view>
	</view>
</template>

<script>
	import ttBar from "@/components/ttBar/ttBar.vue";
	import uQRCode from '@/js_sdk/Sansnn-uQRCode/uqrcode.js';
	export default {
		components: {
			ttBar
		},
		data() {
			return {
				code:'',
				imgUrl:'',
				type:2
			};
		},
		methods: {
			make() {
				uQRCode.make({
					canvasId: 'qrcode',
					componentInstance: this,
					text: this.code.toString(),
					size: 215,
					margin: 10,
					backgroundColor: '#ffffff',
					foregroundColor: '#000000',
					fileType: 'png',
					success: res => {
						this.imgUrl=res
						
					}
				})
			}
		},
		onLoad(cfm) {
			this.code=cfm.code;
			setTimeout(()=>{
				this.make();
			},1000)
		},
		onPullDownRefresh() {
			setTimeout(() => {
				this.make();
				uni.stopPullDownRefresh();
			}, 1500)
		}
	}
</script>

<style lang="less">
	.box{
		padding: 80upx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		text{
			margin-top: 40upx;
			font-size: 32upx;
		}
	}
</style>
